|
1
|
|
|
import { BaseEndpoint, QueryParameters } from './baseEndpoint'; |
|
2
|
|
|
import { |
|
3
|
|
|
MovieAlternativeTitlesResponse, |
|
4
|
|
|
MovieChangesResponse, |
|
5
|
|
|
MovieCreditsResponse, |
|
6
|
|
|
MovieDetailsResponse, |
|
7
|
|
|
MovieExternalIDResponse, |
|
8
|
|
|
MovieImagesResponse, |
|
9
|
|
|
MovieKeywordsResponse, |
|
10
|
|
|
MovieListsResponse, MovieNowPlayingResponse, |
|
11
|
|
|
MoviePopularResponse, |
|
12
|
|
|
MovieRecommendationsResponse, |
|
13
|
|
|
MovieReleaseDatesResponse, |
|
14
|
|
|
MovieReviewsResponse, |
|
15
|
|
|
MovieSimilarMoviesResponse, MovieTopRatedResponse, |
|
16
|
|
|
MovieTranslationsResponse, MovieUpcomingResponse, |
|
17
|
|
|
MovieVideosResponse, |
|
18
|
|
|
} from '../interfaces/movie'; |
|
19
|
|
|
|
|
20
|
|
|
interface QueryWithRegion { |
|
21
|
|
|
region?: string; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Movie Endpoint Class |
|
26
|
|
|
*/ |
|
27
|
|
|
export class Movie extends BaseEndpoint { |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get the primary information about a movie. |
|
31
|
|
|
* @param { number } movieID |
|
32
|
|
|
* @param { QueryParameters } parameters |
|
33
|
|
|
* @param { [string] | null } appendToResponse |
|
34
|
|
|
* @return { Promise<MovieDetailsResponse> } |
|
35
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-details |
|
36
|
|
|
*/ |
|
37
|
|
|
public async details(movieID: number, parameters: QueryParameters = {}, appendToResponse: [string] | null = null): Promise<MovieDetailsResponse> { |
|
38
|
|
|
return this.sendGetRequest(`movie/${movieID}`, this.buildRequestParameters(parameters, appendToResponse)); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Get all of the alternative titles for a movie. |
|
43
|
|
|
* @param { number } movieID |
|
44
|
|
|
* @param { QueryParameters } parameters |
|
45
|
|
|
* @return { Promise<MovieAlternativeTitlesResponse> } |
|
46
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-alternative-titles |
|
47
|
|
|
*/ |
|
48
|
|
|
public async alternativeTitles(movieID: number, parameters: QueryParameters = {}): Promise<MovieAlternativeTitlesResponse> { |
|
49
|
|
|
return this.sendGetRequest(`movie/${movieID}/alternative_titles`, parameters); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the changes for a movie. By default only the last 24 hours are returned. |
|
54
|
|
|
* You can query up to 14 days in a single query by using the `start_date` and `end_date` query parameters. |
|
55
|
|
|
* @param { number } movieID |
|
56
|
|
|
* @param { QueryParameters } parameters |
|
57
|
|
|
* @return { Promise<MovieChangesResponse> } |
|
58
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-changes |
|
59
|
|
|
*/ |
|
60
|
|
|
public async changes(movieID: number, parameters: QueryParameters = {}): Promise<MovieChangesResponse> { |
|
61
|
|
|
return this.sendGetRequest(`movie/${movieID}/changes`, parameters); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the cast and crew for a movie. |
|
66
|
|
|
* @param { number } movieID |
|
67
|
|
|
* @return { Promise<MovieCreditsResponse> } |
|
68
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-credits |
|
69
|
|
|
*/ |
|
70
|
|
|
public async credits(movieID: number): Promise<MovieCreditsResponse> { |
|
71
|
|
|
return this.sendGetRequest(`movie/${movieID}/credits`); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the external ids for a movie. |
|
76
|
|
|
* @param { number } movieID |
|
77
|
|
|
* @return { Promise<MovieExternalIDResponse> } |
|
78
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-external-ids |
|
79
|
|
|
*/ |
|
80
|
|
|
public async externalIDs(movieID: number): Promise<MovieExternalIDResponse> { |
|
81
|
|
|
return this.sendGetRequest(`movie/${movieID}/external_ids`); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get the images that belong to a movie. |
|
86
|
|
|
* Querying images with a language parameter will filter the results. |
|
87
|
|
|
* @param { number } movieID |
|
88
|
|
|
* @param { QueryParameters } parameters |
|
89
|
|
|
* @return { Promise<MovieChangesResponse> } |
|
90
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-images |
|
91
|
|
|
*/ |
|
92
|
|
|
public async images(movieID: number, parameters: QueryParameters = {}): Promise<MovieImagesResponse> { |
|
93
|
|
|
return this.sendGetRequest(`movie/${movieID}/images`, parameters); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Get the keywords that have been added to a movie. |
|
98
|
|
|
* @param { number } movieID |
|
99
|
|
|
* @return { Promise<MovieKeywordsResponse> } |
|
100
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-keywords |
|
101
|
|
|
*/ |
|
102
|
|
|
public async keywords(movieID: number): Promise<MovieKeywordsResponse> { |
|
103
|
|
|
return this.sendGetRequest(`movie/${movieID}/keywords`); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get the release date along with the certification for a movie. |
|
108
|
|
|
* @param { number } movieID |
|
109
|
|
|
* @return { Promise<MovieReleaseDatesResponse> } |
|
110
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-release-dates |
|
111
|
|
|
*/ |
|
112
|
|
|
public async releaseDates(movieID: number): Promise<MovieReleaseDatesResponse> { |
|
113
|
|
|
return this.sendGetRequest(`movie/${movieID}/release_dates`); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Get the videos that have been added to a movie. |
|
118
|
|
|
* @param { number } movieID |
|
119
|
|
|
* @return { Promise<MovieVideosResponse> } |
|
120
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-videos |
|
121
|
|
|
*/ |
|
122
|
|
|
public async videos(movieID: number): Promise<MovieVideosResponse> { |
|
123
|
|
|
return this.sendGetRequest(`movie/${movieID}/videos`); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get a list of translations that have been created for a movie. |
|
128
|
|
|
* @param { number } movieID |
|
129
|
|
|
* @return { Promise<MovieTranslationsResponse> } |
|
130
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-translations |
|
131
|
|
|
*/ |
|
132
|
|
|
public async translations(movieID: number): Promise<MovieTranslationsResponse> { |
|
133
|
|
|
return this.sendGetRequest(`movie/${movieID}/translations`); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Get a list of recommended movies for a movie. |
|
138
|
|
|
* @param { number } movieID |
|
139
|
|
|
* @return { Promise<MovieRecommendationsResponse> } |
|
140
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-recommendations |
|
141
|
|
|
*/ |
|
142
|
|
|
public async recommendations(movieID: number): Promise<MovieRecommendationsResponse> { |
|
143
|
|
|
return this.sendGetRequest(`movie/${movieID}/recommendations`); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* Get a list of similar movies. |
|
148
|
|
|
* This is not the same as the "Recommendation" system you see on the website. |
|
149
|
|
|
* These items are assembled by looking at keywords and genres. |
|
150
|
|
|
* @param { number } movieID |
|
151
|
|
|
* @return { Promise<MovieSimilarMoviesResponse> } |
|
152
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-similar-movies |
|
153
|
|
|
*/ |
|
154
|
|
|
public async similar(movieID: number): Promise<MovieSimilarMoviesResponse> { |
|
155
|
|
|
return this.sendGetRequest(`movie/${movieID}/similar`); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get the user reviews for a movie. |
|
160
|
|
|
* @param { number } movieID |
|
161
|
|
|
* @return { Promise<MovieReviewsResponse> } |
|
162
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-reviews |
|
163
|
|
|
*/ |
|
164
|
|
|
public async reviews(movieID: number): Promise<MovieReviewsResponse> { |
|
165
|
|
|
return this.sendGetRequest(`movie/${movieID}/reviews`); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Get a list of lists that this movie belongs to. |
|
170
|
|
|
* @param { number } movieID |
|
171
|
|
|
* @return { Promise<MovieListsResponse> } |
|
172
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-movie-lists |
|
173
|
|
|
*/ |
|
174
|
|
|
public async lists(movieID: number): Promise<MovieListsResponse> { |
|
175
|
|
|
return this.sendGetRequest(`movie/${movieID}/lists`); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* Get the most newly created movie. |
|
180
|
|
|
* This is a live response and will continuously change. |
|
181
|
|
|
* @return { Promise<MovieDetailsResponse> } |
|
182
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-latest-movie |
|
183
|
|
|
*/ |
|
184
|
|
|
public async latest(): Promise<MovieDetailsResponse> { |
|
185
|
|
|
return this.sendGetRequest(`movie/latest`); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
/** |
|
189
|
|
|
* Get a list of movies in theatres. |
|
190
|
|
|
* This is a release type query that looks for all movies that have a release type of 2 or 3 within the specified date range. |
|
191
|
|
|
* @param { QueryWithRegion } parameters |
|
192
|
|
|
* @return { Promise<MovieNowPlayingResponse> } |
|
193
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-now-playing |
|
194
|
|
|
*/ |
|
195
|
|
|
public async nowPlaying(parameters: QueryWithRegion = {}): Promise<MovieNowPlayingResponse> { |
|
196
|
|
|
return this.sendGetRequest(`movie/now_playing`, parameters as QueryParameters); |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
/** |
|
200
|
|
|
* Get a list of the current popular movies on TMDb. This list updates daily. |
|
201
|
|
|
* @param { QueryWithRegion } parameters |
|
202
|
|
|
* @return { Promise<MoviePopularResponse> } |
|
203
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-popular-movies |
|
204
|
|
|
*/ |
|
205
|
|
|
public async popular(parameters: QueryWithRegion = {}): Promise<MoviePopularResponse> { |
|
206
|
|
|
return this.sendGetRequest(`movie/popular`, parameters as QueryParameters); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Get the top rated movies on TMDb. |
|
211
|
|
|
* @param { QueryWithRegion } parameters |
|
212
|
|
|
* @return { Promise<MovieTopRatedResponse> } |
|
213
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-top-rated-movies |
|
214
|
|
|
*/ |
|
215
|
|
|
public async topRated(parameters: QueryWithRegion = {}): Promise<MovieTopRatedResponse> { |
|
216
|
|
|
return this.sendGetRequest(`movie/popular`, parameters as QueryParameters); |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Get a list of upcoming movies in theatres. |
|
221
|
|
|
* This is a release type query that looks for all movies that have a release type of 2 or 3 within the specified date range. |
|
222
|
|
|
* @param { QueryWithRegion } parameters |
|
223
|
|
|
* @return { Promise<MovieNowPlayingResponse> } |
|
224
|
|
|
* @see https://developers.themoviedb.org/3/movies/get-upcoming |
|
225
|
|
|
*/ |
|
226
|
|
|
public async upcoming(parameters: QueryWithRegion = {}): Promise<MovieUpcomingResponse> { |
|
227
|
|
|
return this.sendGetRequest(`movie/upcoming`, parameters as QueryParameters); |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
/** |
|
231
|
|
|
* Build request parameters |
|
232
|
|
|
* @param { QueryParameters } parameters |
|
233
|
|
|
* @param { [string] | null } appendToResponse |
|
234
|
|
|
* @return QueryParameters |
|
235
|
|
|
*/ |
|
236
|
|
|
private buildRequestParameters(parameters: QueryParameters = {}, appendToResponse: [string] | null = null): QueryParameters { |
|
237
|
|
|
if (appendToResponse !== null) { |
|
238
|
|
|
parameters.append_to_response = appendToResponse.join(','); |
|
239
|
|
|
} |
|
240
|
|
|
return parameters; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
} |
|
244
|
|
|
|